package com.android.youwenchuang.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.android.youwenchuang.bean.MyCustomTabEntity;
import com.android.youwenchuang.databinding.FragmentCircleBinding;
import com.android.youwenchuang.presenter.CirclePresenter;
import com.android.youwenchuang.ui.activity.SendCircleActivity;
import com.android.youwenchuang.ui.adapter.CircleAdapter;
import com.blankj.utilcode.util.ActivityUtils;
import com.flyco.tablayout.listener.CustomTabEntity;

import java.util.ArrayList;

public class CircleFragment extends Fragment {

    private FragmentCircleBinding viewBinding;

    private CircleAdapter adapter = new CircleAdapter();

    private CirclePresenter presenter = new CirclePresenter();
     //展示朋友圈
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        viewBinding = FragmentCircleBinding.inflate(LayoutInflater.from(requireContext()));
        return viewBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        ArrayList<CustomTabEntity> tabEntitys = new ArrayList<>();
        tabEntitys.add(new MyCustomTabEntity("关注"));
        tabEntitys.add(new MyCustomTabEntity("最新"));
        tabEntitys.add(new MyCustomTabEntity("我的"));
        viewBinding.tl1.setTabData(tabEntitys);
        viewBinding.rvList.setLayoutManager(new LinearLayoutManager(requireContext()));
        viewBinding.rvList.setAdapter(adapter);

        viewBinding.btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // 发朋友圈
                ActivityUtils.startActivity(SendCircleActivity.class);
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        adapter.setNewInstance(presenter.getList());

    }
}
